package jwdt.web;

import java.sql.DriverManager;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.ehcache.CacheManager;

import com.ezerg.bonecp.BoneCPDataSource;
import com.ezerg.db.DbPool;
import com.ezerg.web.IRuner;

/**
 * 系统启动时自动初始化配置
 */
public class WebRunner implements IRuner {

	private BoneCPDataSource bc = null;
	private CacheManager cm = null;
	
	public void init() throws Exception {
		bc = DbPool.get().getDataSource();
		cm = CacheManager.getInstance();
		//ApplicationContextFactory.getApplicationContext();		
	}

	public void beforeExecute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// IP 控制
		
	}

	public void afterExecute(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//访问统计
	}

	public void destory() throws Exception {
		bc.close();
		Enumeration<java.sql.Driver> drivers = DriverManager.getDrivers();
		while(drivers.hasMoreElements()) {
			DriverManager.deregisterDriver(drivers.nextElement());
		}
		cm.shutdown();
	}

}
